package com.zero.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result {
    private final static int SUCCESS_CODE = 0;
    private final static int FAIL_CODE = 1;

    private int code;

    private String msg;

    private Object data;

    private long count;

    public Result(int code, String msg, Object data){
        this.code = code;
        this.data = data;
        this.msg = msg;
    }

    public static Result ok(Object data, long count){
        return new Result(0, "带分页的查询成功", data, count);
    }

    public static Result ok(int code, String msg, Object data){
        return new Result(code, msg, data);
    }

    public static Result ok(String msg, Object data){
        return ok(SUCCESS_CODE, msg, data);
    }

    public static Result ok(String msg){
        return ok(msg, null);
    }

    public static Result ok(Object data){
        return ok("操作成功", data);
    }

    public static Result ok(){
        return ok("操作成功", null);
    }

    public static Result fail(int code, String msg, Object data){
        return new Result(code, msg, data);
    }

    public static Result fail(String msg, Object data){
        return fail(FAIL_CODE, msg, data);
    }

    public static Result fail(Object data){
        return fail("操作失败", data);
    }

    public static Result fail(String msg){
        return fail(msg, null);
    }
}
